package com.chen.proxyProvider;

import java.util.Properties;

public class UrlFormat {
    static public String ZMPROXY = "http://webapi.http.zhimacangku.com/getip";

    static public String ADDWHITELIST = "http://wapi.http.linkudp.com/index/index/save_white";

    private String target;

    private Properties properties;

    int num = 1;

    int yys = 0;

    int port = 1;

    int time = 1;

    int type = 2;

    public UrlFormat(String target) {
        this.target = target;
    }

    public UrlFormat(String target, Properties properties) {
        this.target = target;
        this.properties = properties;
    }

    public UrlFormat setNum(int num) {
        this.num = num;
        return this;

    }

    public UrlFormat setYys(int yys) {
        this.yys = yys;
        return this;

    }

    public UrlFormat setPort(int port) {
        this.port = port;
        return this;
    }

    public UrlFormat setTime(int time) {
        this.time = time;
        return this;

    }

    public UrlFormat setType(int type) {
        this.type = type;
        return this;

    }

    public String build() {
        StringBuilder stringBuilder = new StringBuilder(target);
        stringBuilder.append("?");
        stringBuilder.append("num=").append(num);
        stringBuilder.append("&yys=").append(yys);
        stringBuilder.append("&port=").append(port);
        stringBuilder.append("&time=").append(time);
        stringBuilder.append("&type=").append(type);
        return stringBuilder.toString();
    }

    public String white(String ip) {
        if (properties == null) {
            throw new NullPointerException("properties没有配置好");
        }
        StringBuilder stringBuilder = new StringBuilder(target);
        stringBuilder.append("?");
        stringBuilder.append("neek=").append(properties.getProperty("neek"));
        stringBuilder.append("&appkey=").append(properties.getProperty("appkey"));
        stringBuilder.append("&white=").append(ip);
        return stringBuilder.toString();
    }
}
